package server.exportimport;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import abstractservlet.AbstractServlet;
import autoservice.api.controller.IAutoservice;
import controllers.Autoservice;

@WebServlet("/Export")
public class Export extends AbstractServlet {
	private static final long serialVersionUID = 1L;
	private IAutoservice autoservice = Autoservice.getInstance();
	private static final String EXPORT = "export";
	private static final String URL = "url";
	private static final String MASTERS = "masters";
	private static final String ORDERS = "orders";
	private static final String EXPORT_PAGE = "/exportimportpages/ExportPage.jsp";
	private static final String DELIMITER = " ";

	public Export() {
		super();

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String object = request.getParameter(EXPORT);
		String path = request.getParameter(URL);
		String answer = null;
		if (object.equals(MASTERS)) {
			answer = autoservice.exportMasters(path).get(0);
		} else if (object.equals(ORDERS)) {
			answer = autoservice.exportOrders(path).get(0);
		} else {
			answer = autoservice.exportGarages(path).get(0);
		}
		super.navigate(request, response, EXPORT + DELIMITER + object, answer,
				EXPORT_PAGE);

	}

}
